package com.spzx.product.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.log.annotation.Log;
import com.spzx.common.log.enums.BusinessType;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.common.security.annotation.RequiresPermissions;
import com.spzx.product.domain.Brand;
import com.spzx.product.service.BrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "品牌接口管理")
@RestController
@RequestMapping("/brand")
public class BrandController extends BaseController {

    @Autowired
    private BrandService brandService;

    @RequiresPermissions("product:brand:list")
    @Operation(summary = "查询品牌列表")
    @GetMapping("/list")
    public TableDataInfo list(Brand brand) {
        startPage();
        List<Brand> list = brandService.selectBrandList(brand);
        return getDataTable(list);
    }

    @RequiresPermissions("product:brand:query")
    @Operation(summary = "获取品牌详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        Brand brand = brandService.findBrandInfo(id);
        return success(brand);
    }

    @Log(title = "品牌管理", businessType = BusinessType.UPDATE)
    @RequiresPermissions("product:brand:edit")
    @Operation(summary = "修改品牌详细信息")
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated Brand brand) {
        brandService.update(brand);
        return success();
    }

    @Log(title = "品牌管理", businessType = BusinessType.INSERT)
    @RequiresPermissions("product:brand:add")
    @Operation(summary = "新增品牌")
    @PostMapping
    public AjaxResult save(@RequestBody @Validated Brand brand) {
        brandService.save(brand);
        return success();
    }

    @Log(title = "品牌管理", businessType = BusinessType.DELETE)
    @RequiresPermissions("product:brand:remove")
    @Operation(summary = "删除品牌")
    @DeleteMapping("/{ids}")
    public AjaxResult deleteBrand(@PathVariable("ids") Long[] ids) {
        brandService.deleteBrand(ids);
        return success();
    }

    @InnerAuth
    @Operation(summary = "获取全部品牌")
    @GetMapping("/getBrandAll")
    public AjaxResult getBrandAll() {
        List<Brand> list = brandService.getBrandAll();
        return success(list);
    }
}


